if (window.plus) {
    ready();
} else {
    document.addEventListener('plusready', ready, false);
}

$(function(){
  if(AGENT_CLIENT.WEB){
    ready();
  } 
})

function ready() {
    var thisPage = {},
        user = {},
        html = [];
        
    var feedbackPage = function(){
      this.init();
    };
    feedbackPage.prototype = {
      init:function(){
        this.initData();
        this.bindEvent();
      },
      initData:function(){
        user = getLocalStorage(STORAGE_MANAGER.user);
        if(!user){
          redirect("../account/login.html");
        }
      }, 
      bindEvent:function(){
        
        //点击回退
        $("#back").on("click", function(){
          back();
        });
        
        //切换类型
        $("p[name='feedType']>span").on("click", function(){
          $(this).addClass("huaguo").siblings().removeClass("huaguo");
        });
        
        $("#feedbackContent").on("input", function(){
          
          if("" == $(this).val()){
            $("#commit").unbind().addClass("gray_color");
          }else{
            $("#commit").unbind().removeClass("gray_color").on("click", function(){
              var requestData = {
                memberId:user.id,
                type:$("span.huaguo").attr("tip"),
                content:$("#feedbackContent").val(),
              };
              if($("#mobile").val()){
	              if( isTelephone($("#mobile").val()) ){
	                requestData.mobile = $("#mobile").val();
	              }else if( is_email($("#mobile").val()) ){
	                requestData.email = $("#mobile").val();
	              }else{
	                $.toast("联系方式不正确");
	                return false;                
	              }
							}
              $.ajax({
              	type:"POST",
              	url: CONFIG_MANAGER.RequstUrl + "v1/feedback/member",
              	async:true,
              	data:requestData,
              	headers:{ token:user.toke }
              }).done(function(data){
                $.alert("您提交的反馈我们已经收到，感谢您的参与！",function(){
                  //redirect("mylife.html");
                  back();
                });
              }).fail(function(data){
                var infor = JSON.parse(data);
                $.alert(infor.Message);
              });
            });
          }
          
        });
      }
    };
    thisPage = new feedbackPage();
}
